/*
 * Wazuh Vulnerability scanner - Database Feed Manager
 * Copyright (C) 2015, Wazuh Inc.
 * Feb 28, 2023.
 *
 * This program is free software; you can redistribute it
 * and/or modify it under the terms of the GNU General Public
 * License (version 2) as published by the FSF - Free Software
 * Foundation.
 */

#ifndef _GLOBALDATA_HPP
#define _GLOBALDATA_HPP

#include "json.hpp"
#include "singleton.hpp"
#include <mutex>
#include <shared_mutex>

/**
 * @brief Class to manage global maps data.
 */
class GlobalData final : public Singleton<GlobalData>
{
    mutable std::shared_mutex m_mutex;
    nlohmann::json m_vendorMaps;
    nlohmann::json m_osCpeMaps;
    std::string m_managerName;

public:
    /**
     * @brief Set vendor map data.
     * @param vendor Vendor data.
     */
    void vendorMaps(const nlohmann::json& vendor)
    {
        std::unique_lock<std::shared_mutex> lock(m_mutex);
        m_vendorMaps = vendor;
    }

    /**
     * @brief Set OS CPE map data.
     * @param osCpe OS CPE data.
     */
    void osCpeMaps(const nlohmann::json& osCpe)
    {
        std::unique_lock<std::shared_mutex> lock(m_mutex);
        m_osCpeMaps = osCpe;
    }

    /**
     * @brief Set manager name.
     * @param managerName Manager name.
     */
    void managerName(const std::string& managerName)
    {
        m_managerName = managerName;
    }

    /**
     * @brief Get vendor map data.
     * @return vendor map data.
     */
    nlohmann::json vendorMaps() const
    {
        std::shared_lock<std::shared_mutex> lock(m_mutex);
        return m_vendorMaps;
    }

    /**
     * @brief Get OS CPE map data.
     * @return OS CPE data.
     */
    nlohmann::json osCpeMaps() const
    {
        std::shared_lock<std::shared_mutex> lock(m_mutex);
        return m_osCpeMaps;
    }

    /**
     * @brief Get manager name.
     * @return Manager name.
     */
    std::string_view managerName() const
    {
        return m_managerName;
    }
};

#endif // _GLOBALDATA_HPP
